﻿namespace HuwmanCode

open System

[<RequireQualifiedAccess>]
module Option =
    /// <summary>
    /// Creates a 't option based on the success parameter.
    /// </summary>
    /// <param name="sucess">A boolean value. False = None, True = Some(value).</param>
    /// <param name="value">The value.</param>
    let create(success, value) =
        match success with
        | false -> None
        | true -> Some(value)

    /// <summary>
    /// Converts a 't option option to 't option.
    /// </summary>
    let peel(value:'t option option) =
        match value with
        | Some v -> v
        | None -> None

[<AutoOpen>]
module OptionExtension =
    type Option<'t> with
        member x.map(mf:'t->'m, defValue) =
            match x with
            | Some o -> mf o
            | None -> defValue

        member x.map(mf:'t->'m) =
            x.map(mf, Unchecked.defaultof<_>)

        